//
//  PhotoCollectionViewCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-30.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "PhotoCollectionViewCell.h"
#import "UIImageView+WebCache.h"

@implementation PhotoCollectionViewCell

- (void)dealloc
{
    [_mountLabel release];
    [_imageView release];
    [_nameTextView release];
    [_hotTravel release];
    [_waypoints release];
    [_mountLabel release];
    [_waypointsDic release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.imageView = [[UIImageView alloc] init];
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.imageView];
        [_imageView release];
        
        // 显示第几张图片
        self.mountLabel = [[UILabel alloc] init];
        self.mountLabel.textColor = [UIColor whiteColor];
        [self.imageView addSubview:self.mountLabel];
        [_mountLabel release];
        
        self.dateLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.dateLabel];
        self.dateLabel.textColor = [UIColor whiteColor];
        self.dateLabel.font = [UIFont systemFontOfSize:10];
        [_dateLabel release];
        
        self.nameTextView = [[UITextView alloc] init];
        self.nameTextView.alpha = 1;
        // 背景颜色透明
        self.nameTextView.backgroundColor = [UIColor colorWithRed:255 green:0 blue:255 alpha:0];
        self.nameTextView.textColor = [UIColor whiteColor];
        // 让textView只能滑动不能编辑
        self.nameTextView.editable = NO;
        [self.contentView addSubview:self.nameTextView];
        [_nameTextView release];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.imageView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height);
//    NSURL *url = [NSURL URLWithString:[self.waypointsDic objectForKey:@"photo"]];
//    [self.imageView setImageWithURL:url];

    // 图片位置
    self.mountLabel.frame = CGRectMake(self.contentView.frame.size.width / 2 - 60, 10, 120, 40);
    
    
    self.nameTextView.frame = CGRectMake(10, self.contentView.frame.size.height - 110, self.contentView.frame.size.width - 20, 50);
//    self.nameTextView.text = [self.waypointsDic objectForKey:@"text"];
    
    self.dateLabel.frame = CGRectMake(10, self.contentView.frame.size.height - 55, self.contentView.frame.size.width, 10);
//    UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(10, self.contentView.frame.size.height - 15, 5, 10)];
//    if ([self.waypointsDic objectForKey:@"poi"] != nil) {
//        [view setImage:[[self.waypointsDic objectForKey:@"poi"] objectForKey:@"icon"]];
//        self.dateLabel.text = [NSString stringWithFormat:@"  %@  %@", [[self.waypointsDic objectForKey:@"poi"] objectForKey:@"name"], [self.waypointsDic objectForKey:@"local_time"]];
//    }else{
//    self.dateLabel.text = [NSString stringWithFormat:@"⌚️ %@", [self.waypointsDic objectForKey:@"local_time"]];
//    NSLog(@"%@        =====", self.nameTextView.text);
    
    
//    }
//    [self.dateLabel addSubview:view];
//    [view release];
}

-(void)setWaypointsDic:(NSDictionary *)waypointsDic
{
    if (_waypointsDic != waypointsDic) {
        [_waypointsDic release];
        _waypointsDic = [waypointsDic retain];
    }
    NSURL *url = [NSURL URLWithString:[_waypointsDic objectForKey:@"photo"]];
    [self.imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"picLoading.png"]];
    
    self.nameTextView.text = [_waypointsDic objectForKey:@"text"];
    self.nameTextView.textColor = [UIColor whiteColor];

    self.dateLabel.text = [NSString stringWithFormat:@" ⌚️ %@", [self.waypointsDic objectForKey:@"local_time"]];
//    NSLog(@"%@text========", self.nameTextView.text);
}



@end
